home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / game / patch / jst32b_dev.lha / jst_dev / sources / src / DiskTools / boot2file.c next >
C/C++ Source or Header  |  2000-03-31  |  2KB  |  102 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <signal.h>
  4.  
  5. #include <dos/dos.h>
  6. #include <proto/dos.h>
  7. #include <proto/exec.h>
  8. #include <exec/execbase.h>
  9. #include <exec/libraries.h>
  10. #include <exec/memory.h>
  11. #include <pragmas/dos_pragmas.h>
  12. #include <string.h>
  13.  
  14.  
  15. extern struct ExecBase *SysBase;
  16.  
  17. extern APTR InitTrackDisk(ULONG);
  18. extern void ShutTrackDisk(void);
  19. extern void ReadDosTrack(ULONG,APTR);
  20. extern ULONG CheckDiskIn (void);
  21.  
  22. APTR trackBuffer=0L;
  23. FILE *f=0L;
  24. char *charunit="DF0:";
  25. int allocated=0,diskinit=0;
  26.  
  27. void CloseAll(char *mess)
  28.  
  29. {
  30. if (mess) printf("** %s\n",mess);
  31.  
  32. if (diskinit) ShutTrackDisk();
  33. if (allocated) Inhibit(charunit,FALSE);
  34. if (trackBuffer) FreeMem(trackBuffer,512*11);
  35. if (f) fclose(f);
  36. exit(0);
  37. }
  38.  
  39. void BreakHandle(int code)
  40.  
  41. {
  42. CloseAll("User break");
  43. }
  44.  
  45.  
  46. int findArg(unsigned int argc,char ** argv,char * argstr)
  47. {
  48.   int argl,i;
  49.  
  50.   argl=strlen(argstr);
  51.  
  52.   for (i=0;i<argc;i++)
  53.     if (!strncmp(argv[i],argstr,argl)) return i;
  54.  
  55.   return 0;
  56. }
  57.  
  58.  
  59. main(unsigned int argc,char ** argv)
  60.  
  61.  
  62. {
  63.   ULONG i;
  64.   ULONG diskunit;
  65.  
  66.   signal(SIGINT,BreakHandle);
  67.  
  68.   if (argc<3) {printf("Boot2File V1.1, a boot image maker by Jean-François Fabre\nUsage : boot2file <unit number> <filename>\n");if (!argc) Delay(200);exit(0);}
  69.  
  70.   
  71.   diskunit=(ULONG)argv[1][0]-'0';
  72.  
  73.   if ((diskunit>3)||(diskunit<0)) {printf("** Unit %d unavailable\n",diskunit);CloseAll(0);}
  74.  
  75.   charunit[2]=diskunit+'0';
  76.  
  77.   if (SysBase->LibNode.lib_Version>36)
  78.     {
  79.     if(Inhibit(charunit,DOSTRUE)==FALSE) CloseAll("Can't allocate device !");
  80.     allocated=1;
  81.     }
  82.  
  83.   InitTrackDisk(diskunit);
  84.   diskinit=1;
  85.   if (CheckDiskIn()) {printf("** No disk in unit %d !\n",diskunit);CloseAll(NULL);}
  86.  
  87.   f=fopen(argv[2],"wb");
  88.  
  89.   if (f==0L) {printf("Can't create file !\n");CloseAll(0);}
  90.  
  91.   trackBuffer=AllocMem(512*11,MEMF_CHIP|MEMF_CLEAR);  
  92.   if (trackBuffer==0L) CloseAll("Can't allocate memory.");
  93.  
  94.   for (i=0;i<2;i++)
  95.   {
  96.     ReadDosTrack(i,trackBuffer);
  97.     if (fwrite(trackBuffer,1,512*11,f)!=512*11) CloseAll("** Disk full !");
  98.   }
  99.  
  100.   CloseAll(NULL);
  101. }
  102.